<?php
session_start();
$_SESSION['hallpass'] = true;
include "DBConnection.php";
require_once "./Objects/User.php";
require_once "security.php";

$email=$_SESSION['email'];
$connection = new Connection(); //connect to the DB

$query = "SELECT firstname, lastname, w_id, pass, salt, phone
        FROM workertrack.temp_user
        WHERE w_email = '$email';"; 

$resultset = $connection->execute_query($query);	//result gets the info from the DB
$result = mysql_fetch_array($resultset);
	
	$firstname = $result[0];
	$lastname = $result[1];
	$w_id = $result[2];
	$pass = $result[3];
	$salt = $result[4];
	$phone = $result[5];
	
$query1="INSERT INTO workertrack.worker (w_email, firstname, lastname,w_id,pass,salt,phone)
VALUES ('$email','$firstname','$lastname','$w_id','$pass','$salt','$phone')";
$connection->execute_query($query1);

$query2="DELETE FROM workertrack.temp_user WHERE w_email='$email'";
$connection->execute_query($query2);

$connection->close_connection();

$_SESSION['login']=1;
$name=explode("@", $email);
$_SESSION['userid']=$name[0];
$_SESSION['usertype']="worker";
header('Location: ../index.php');
$_SESSION['hallpass'] = false;
?>